package me.jiatao.jetpack;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import me.jiatao.jetpack.databinding.ActivityDataBindingBinding;
import me.jiatao.jetpack.databinding.MyEventHanding;
import me.jiatao.jetpack.databinding.User;

public class DataBindingActivity extends AppCompatActivity {
    private User user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_data_binding);

        //默认情况下，绑定类将根据 layout 文件的名称生成，首字母大写的命名规范，并添加 “Binding” 后缀
        //这里的layout名称是activity_data_binding 所以生成绑定类ActivityDataBindingBinding
        ActivityDataBindingBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_data_binding);
        user = new User("Tao", "Jia");
        binding.setUser(user);

        //事件绑定
        MyEventHanding myEventHanding = new MyEventHanding();
        binding.setEventHanding(myEventHanding);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                user.setFirstName("JiaJia");
                user.setLastName("TaoTao");
                user.address.set("临沂");
                Toast.makeText(DataBindingActivity.this,user.toString(), Toast.LENGTH_SHORT).show();
            }
        }, 2000);



    }
}
